<#include "/includes/vars.inc">  
<@pp.dropOutputFile />
<#list entities.entity as entity>
    <#assign entityName = entity.@name>
    <#assign managedBean = entity.@name?uncap_first+"Controller">
        <#list entity["one-to-many"] as rel>
        <#assign entityRel = rel.@entity>
        <@pp.changeOutputFile name="${webDir}/jeecode/"+entity.@name?uncap_first+"/include/"+entity.@name?cap_first+"${entityRel?cap_first}OTM.xhtml" />
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition> 
        <#if !(rel.@mappedBy[0]??)>
        <#assign managedBeanRel = rel.@entity?uncap_first+"Controller">
        <#assign managedBean = entity.@name?uncap_first+"Controller">
        <h:panelGroup id="otm">
            <h:panelGrid columns="4" cellpadding="2">
                <h:outputLabel for="us" value="${r"#{"}msg.search${r"}"} ${r"#{"}msg.${entityRel?uncap_first}${r"}"}:"/>
                <p:autoComplete id="us"
                                value="${r"#{"}${managedBean}${r"."}${entityRel?uncap_first}${r"}"}"
                                completeMethod="${r"#{"}${managedBeanRel}${r".complete"}${entityRel}s${r"}"}"
                                forceSelection="true"
                                var="${entityRel?uncap_first}"
                                itemLabel="${r"#{"}${entityRel?uncap_first}${r"}"}"
                                itemValue="${r"#{"}${entityRel?uncap_first}${r"}"}"
                                converter="${entityRel?uncap_first}Converter"
                                disabled="${r"#{"}${managedBean}${r"."}${entityRel?uncap_first}${r".persisted"}${r"}"}"
                                size="60">  
                    <p:ajax event="itemSelect" update="otm" />
                </p:autoComplete>
                <p:commandButton  actionListener="${r"#{"}${managedBean}${r".cancelAdd"}${entityRel}To${entityName}${r"}"}"
                                  update="otm"
                                  icon="ui-icon ui-icon-close"
                                  disabled="${r"#{"}!${managedBean}${r"."}${entityRel?uncap_first}${r".persisted"}${r"}"}">   
                </p:commandButton>
                <p:commandButton  actionListener="${r"#{"}${managedBean}${r".add"}${entityRel}To${entityName}${r"}"}"
                                  update="otm,data"
                                  icon="ui-icon ui-icon-check"
                                  disabled="${r"#{"}!${managedBean}${r"."}${entityRel?uncap_first}${r".persisted"}${r"}"}">   
                </p:commandButton>
            </h:panelGrid>
        </h:panelGroup> 
        </#if>
        <h:panelGroup id="data">
            <p:dataTable        
                value="${r"#{"}${managedBean}${r".current."}${rel?parent.@name}${r"}"}"
                var="${entityRel?uncap_first}"
                styleClass="apm-dataTable"
                paginator="true"
                paginatorPosition="bottom"
                rows="10">
                <f:facet name="header">
                </f:facet>
            
                <#list entities.entity as entityRef>
                    <#if entityRef.@name = entityRel >
                        <#list entityRef.column as column>
                            <#if column.@primary = "false" >
                <p:column  headerText="${r"#{"}msg.${entityRel?uncap_first}${column.@name?cap_first?replace(".","_")}${r"}"}">
                                <#if column.@type = "Date" >
                    <h:outputText value="${r"#{"}${entityRel?uncap_first}.${column.@name}${r"}"}">
                      <f:convertDateTime pattern="${config.date.@pattern}" timeZone="${r"#{"}utilController.timeZone}" />
                    </h:outputText>
                                <#else>
                    <h:outputText value="${r"#{"}${entityRel?uncap_first}.${column.@name}${r"}"}"/>
                                </#if>
                </p:column>
                             </#if>
                        </#list>
                    </#if>
                </#list>
                <f:facet name="footer">
                </f:facet>
            </p:dataTable>
        </h:panelGroup>
    </ui:composition>

</html>
    </#list>

</#list>